package com.engine.hikvision.web;

import com.engine.common.util.ParamUtil;
import com.engine.hikvision.service.HikVisionService;
import com.engine.hikvision.service.impl.HikVisionServiceImpl;
import com.google.gson.Gson;
import weaver.general.BaseBean;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import java.util.HashMap;
import java.util.Map;

public class HikVisionWebAction extends BaseBean {

    HikVisionService hikVisionService = new HikVisionServiceImpl();

    @POST
    @Path("/syncPersonDoorData")
    @Produces({"application/json"})
    public String subscribeEvent(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> paramMap = getMap(request);
        Map<String, Object> resultMapA =  hikVisionService.syncPersonDoorData(paramMap);
        return new Gson().toJson(resultMapA);
    }

    public Map<String, Object> getMap( HttpServletRequest request) {
        Map<String,Object>  map = new HashMap<String, Object>();
        map = ParamUtil.request2Map(request);
        map.put("operateIp", request.getRemoteAddr());
        return map;
    }
}
